package top.infopub.enums.mkt;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public enum BackMechEnum {
    BACK_MECH1("1", "政府付费"),
    BACK_MECH2("2", "可行性缺口补助"),
    BACK_MECH3("3", "使用者付费");

    private String code;

    private String name;

    BackMechEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    public static BackMechEnum getByCode(String code) {
        if (StringUtils.isBlank(code)) return null;
        for (BackMechEnum bme : BackMechEnum.values()) {
            if (StringUtils.equals(code, bme.getCode())) {
                return bme;
            }
        }
        return null;
    }

    public static List<Map<String, String>> asList() {
        List<Map<String, String>> list = new ArrayList<>();
        Map<String, String> map;
        for (BackMechEnum bme : BackMechEnum.values()) {
            map = new HashMap<>();
            map.put("code", bme.getCode());
            map.put("name", bme.getName());
            list.add(map);
        }
        return list;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
